#include"stack.h"
#include<stdio.h>

contentType getToken(char* symbol, int* index) {

	*symbol = expr[*index];

	*index = *index + 1;
	switch (*symbol) {
	case '(':
		return LEFT_PARE;
	case ')':
		return RIGHT_PARE;
	case '+':
		return ADD;
	case '-':
		return SUB;
	case '*':
		return MUL;
	case '/':
		return DIV;
	case '%':
		return MOD;
	case '\0':
		return EOS;
	default:
		return NUM;
	}
}


int eval(Stack* s) {
	char symbol;
	int op1;
	int op2;
	int result;

	int index=0;
	contentType token;
	token = getToken(&symbol, &index);
	while (token != EOS) {
		if (token == NUM) {
			Push(s, symbol-'0');
		}
		else {
			Pop(s, &op2);
			Pop(s, &op1);
			switch (token) {
			case ADD:
				Push(s, op1 + op2);
				break;
			case SUB:
				Push(s, op1 - op2);
				break;
			case MUL:
				Push(s, op1 * op2);
				break;
			case DIV:
				Push(s, op1 / op2);
				break;
			case MOD:
				Push(s, op1 % op2);
				break;
			default:
				break;
			}

		}
		token = getToken(&symbol, &index);

	}
	Pop(s, &result);
	printf("%d\n", result);
	return 1;
}

int main() {

	Stack s;

	InitStack(&s);

	eval(&s);
	return 0;
}